package com.hontech.bv.conn.api

import com.hontech.bv.conn.Proto
import com.hontech.bv.conn.SerialPortMod
import com.hontech.bv.conn.serial.Uint16
import com.hontech.bv.conn.serial.Uint8

object Arm {

    suspend fun elevatorCtrl(position: Int) {
        SerialPortMod.request(
            Proto.REQ_ARM_ELEVATOR_CTRL,
            Proto.ID_ARM,
            arrayOf(Uint16(position))
        ).assert("升降测试")
    }

    suspend fun jawCtrl(type: Int) {
        SerialPortMod.request(
            Proto.REQ_ARM_JAW_CTRL,
            Proto.ID_ARM,
            arrayOf(Uint8(type))
        ).assert("夹爪测试")
    }

    suspend fun armCtrl(type: Int) {
        SerialPortMod.request(
            Proto.REQ_ARM_ARM_CTRL,
            Proto.ID_ARM,
            arrayOf(Uint8(type))
        ).assert("机械臂测试")
    }

    suspend fun armRun(p1: Int, p2: Int, speed: Int) {
        SerialPortMod.request(
            Proto.REQ_ARM_ARM_RUN,
            Proto.ID_ARM,
            arrayOf(Uint16(p1), Uint16(p2), Uint16(speed))
        ).assert("机械臂运动测试")
    }

    suspend fun doFilm() {
        SerialPortMod.request(
            Proto.REQ_ARM_FILM_CTRL,
            Proto.ID_ARM,
            arrayOf()
        ).assert("封膜")
    }

    suspend fun doPick() {
        SerialPortMod.request(
            Proto.REQ_ARM_PICK,
            Proto.ID_ARM,
            arrayOf()
        ).assert("取货")
    }

    suspend fun doInit() {
        SerialPortMod.request(
            Proto.REQ_ARM_INIT,
            Proto.ID_ARM,
            arrayOf()
        ).assert("初始化")
    }

    suspend fun doPosition(type: Int) {
        SerialPortMod.request(
            Proto.REQ_ARM_RUN_POSITION,
            Proto.ID_ARM,
            arrayOf(Uint8(type))
        ).assert("运动到某位置")
    }

}